% fname: routing_oddeven__sel_bufferlevel__topology_8x8__.m
% ./noxim -routing oddeven -sel bufferlevel -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 4 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_bufferlevel__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        20.6612      0.0134894            114            797           6367
           0.0015        20.3828      0.0137076             85            768           6141
           0.0015        17.9542      0.0121947             89            743           5951
           0.0015        20.1351      0.0136228            123            777           6212
           0.0015        20.4265      0.0132694             88            769           6157
           0.0015        19.1542      0.0128556             92            746           5965
           0.0015        20.6334      0.0138319            119            802           6418
           0.0015        19.8118      0.0122419            106            760           6072
           0.0015        19.0429       0.012425             70            746           5964
           0.0015        20.1808      0.0130424            102            769           6156
           0.0015        19.9973      0.0129655             98            753           6016
           0.0015        19.0722      0.0118387            112            734           5872
           0.0015        21.8305       0.013911            174            820           6566
           0.0015        20.2612      0.0131926            100            804           6438
           0.0015        19.0654      0.0125389            109            765           6119
           0.0015        19.9563      0.0127606             75            755           6023
           0.0015        21.5935      0.0134211            105            765           6120
           0.0015        21.7659      0.0133583            106            803           6412
           0.0015        21.7247      0.0132062            108            792           6339
           0.0015        19.7411      0.0119652             79            730           5839
           0.0017        23.6099      0.0144863            150            928           7417
           0.0017         21.315      0.0143197            117            873           6988
           0.0017        21.6909       0.014225            112            854           6828
           0.0017        21.2986      0.0142667            108            854           6848
           0.0017         21.738      0.0139959            107            855           6830
           0.0017         23.719      0.0145354            207            872           6977
           0.0017        22.1887      0.0148901            102            864           6909
           0.0017        21.5099       0.014002            104            855           6833
           0.0017          22.26      0.0143475            117            846           6772
           0.0017        22.2953      0.0138629            139            860           6876
           0.0017        21.7891      0.0131123            122            773           6189
           0.0017        20.8691      0.0152823             95            886           7091
           0.0017        22.3711      0.0145318            106            857           6859
           0.0017        21.8471      0.0141843            182            837           6695
           0.0017        20.8135      0.0138074             89            842           6738
           0.0017        23.2959      0.0147275            112            899           7187
           0.0017        22.7508      0.0150847            108            891           7120
           0.0017        21.7568      0.0143453            124            847           6771
           0.0017        21.3126      0.0137758            113            867           6943
           0.0017        20.5855      0.0139915            106            825           6604
           0.0019        22.7613      0.0151766            112            955           7649
           0.0019        23.4585      0.0156885            148            988           7907
           0.0019        24.7666       0.017161            110           1011           8100
           0.0019        24.6355      0.0155403            229            963           7708
           0.0019        21.7811      0.0153407            136            950           7609
           0.0019        23.6241      0.0158047            127           1011           8092
           0.0019        23.6943      0.0161674            130            952           7631
           0.0019        23.6936      0.0163083            118            979           7828
           0.0019        22.7944      0.0157599            106            992           7943
           0.0019        24.7194      0.0158085            212            980           7841
           0.0019        25.3177      0.0166521            136           1001           7993
           0.0019        23.5332      0.0150605            130            934           7470
           0.0019        23.6632      0.0153367            138            950           7607
           0.0019        24.8888      0.0159435            141            989           7908
           0.0019        22.4024       0.014502            123            927           7425
           0.0019        22.0633      0.0155363            122            963           7706
           0.0019        23.3389      0.0156475            146            953           7636
           0.0019        22.9919      0.0162172            113            988           7914
           0.0019        24.6863       0.015377            159            953           7627
           0.0019        24.0261      0.0157857            146            995           7956
           0.0021         27.695      0.0180146            175           1082           8647
           0.0021        25.1311      0.0174959            141           1068           8538
           0.0021        24.8577      0.0168393            112           1061           8487
           0.0021        24.7736      0.0175927            142           1091           8726
           0.0021        25.6111      0.0177766            158           1085           8675
           0.0021        26.9341       0.017918            174           1093           8744
           0.0021        25.5952      0.0171726            166           1082           8655
           0.0021        25.2263      0.0178835            165           1056           8441
           0.0021        25.8034      0.0167937            218           1058           8464
           0.0021        27.5581      0.0168194            193           1059           8477
           0.0021        24.0949      0.0167321            136           1054           8433
           0.0021        26.1285       0.016918            193           1082           8662
           0.0021        24.6499      0.0163849            114           1031           8258
           0.0021        25.4659       0.017246            132           1069           8554
           0.0021          24.69      0.0170867            188           1058           8475
           0.0021        28.1661      0.0178566            169           1090           8714
           0.0021        26.4523       0.016707            173           1070           8554
           0.0021        25.6744      0.0175932            145           1038           8304
           0.0021        31.3212      0.0170902            656           1043           8340
           0.0021        25.8083      0.0175867            174           1090           8723
           0.0023         32.798      0.0194107            298           1223           9783
           0.0023        30.8581      0.0187044            233           1177           9427
           0.0023        29.3263      0.0189127            215           1192           9532
           0.0023        26.6015      0.0185179            185           1167           9333
           0.0023        28.1092      0.0184778            296           1145           9165
           0.0023        31.3831      0.0189266            317           1193           9539
           0.0023        26.4931      0.0170176            209           1089           8713
           0.0023        29.6374      0.0187258            213           1161           9288
           0.0023        29.4527       0.018621            189           1173           9385
           0.0023        26.7735       0.018254            146           1148           9200
           0.0023        28.7695      0.0185119            401           1167           9330
           0.0023        26.6377      0.0180952            155           1140           9120
           0.0023        31.9975      0.0194153            294           1204           9630
           0.0023        32.9418      0.0190625            359           1220           9760
           0.0023        31.9071      0.0183594            209           1173           9400
           0.0023        29.4755      0.0187798            173           1182           9465
           0.0023        30.3781      0.0188569            210           1169           9353
           0.0023        29.5138      0.0179048            309           1127           9024
           0.0023        33.6462      0.0197848            201           1207           9655
           0.0023        27.9015      0.0185575            210           1168           9353
           0.0025         32.465      0.0198711            197           1271          10174
           0.0025        34.2249      0.0202117            285           1254          10025
           0.0025        38.4419      0.0203552            364           1283          10259
           0.0025        44.5868      0.0201528            321           1268          10157
           0.0025        30.7468      0.0194355            151           1244           9951
           0.0025        35.1992      0.0203988            428           1285          10281
           0.0025        36.1376      0.0198512            216           1250          10005
           0.0025        33.6079      0.0198613            294           1270          10169
           0.0025        34.5213      0.0194883            336           1247           9978
           0.0025        35.1426      0.0200218            352           1262          10091
           0.0025         31.655      0.0197129            167           1261          10093
           0.0025        31.9611      0.0196797            254           1261          10076
           0.0025        42.8677      0.0212539            434           1361          10882
           0.0025        32.3215      0.0193867            177           1241           9926
           0.0025        33.5027      0.0207863            209           1289          10310
           0.0025        35.3483       0.020166            258           1289          10325
           0.0025        38.3477      0.0199844            291           1280          10232
           0.0025        29.5555      0.0194395            188           1244           9953
           0.0025        36.2105      0.0201875            351           1292          10336
           0.0025        37.1333      0.0202321            298           1275          10197
           0.0027        43.5663      0.0220198            396           1388          11098
           0.0027        39.7676      0.0220575            399           1390          11117
           0.0027        42.0202       0.021668            456           1386          11094
           0.0027        43.8605      0.0217344            367           1391          11128
           0.0027        39.7697      0.0216492            376           1342          10738
           0.0027        72.9704      0.0236091            922           1488          11899
           0.0027         51.593      0.0223398            725           1430          11438
           0.0027        74.9084      0.0221797           1287           1419          11356
           0.0027        38.9933      0.0214206            248           1349          10796
           0.0027         62.137      0.0228274           1081           1438          11505
           0.0027         34.485      0.0219839            334           1363          10904
           0.0027        40.5779       0.021666            350           1386          11093
           0.0027        45.9978      0.0215137            431           1377          11015
           0.0027        43.0036      0.0217877            597           1372          10981
           0.0027        47.1155       0.022582            402           1446          11562
           0.0027        53.8607       0.021998           1062           1407          11263
           0.0027        44.3513      0.0218008            455           1395          11162
           0.0027        34.3699      0.0218164            263           1395          11170
           0.0027         48.292      0.0225179            490           1418          11349
           0.0027        40.1168      0.0213906            320           1370          10952
           0.0029        55.9179      0.0231885            607           1461          11687
           0.0029        60.8953      0.0229863            864           1471          11769
           0.0029        66.1585      0.0232383            649           1489          11898
           0.0029        70.5436      0.0247843            492           1538          12293
           0.0029        53.3821      0.0226621            495           1450          11603
           0.0029        53.8217      0.0232109            544           1486          11884
           0.0029        42.9596      0.0228056            250           1436          11494
           0.0029        48.8457      0.0235317            348           1484          11860
           0.0029        55.0291      0.0232944            594           1444          11554
           0.0029        41.4434      0.0225853            515           1423          11383
           0.0029        73.8485      0.0230675           1100           1452          11626
           0.0029        41.3522      0.0223926            323           1434          11465
           0.0029        57.4855      0.0231191            618           1479          11837
           0.0029        58.4937       0.023668            396           1515          12118
           0.0029         49.466      0.0220684            594           1412          11299
           0.0029        94.7484      0.0244688            894           1566          12528
           0.0029        56.1361      0.0229785            828           1470          11765
           0.0029        46.4354      0.0237012            570           1516          12135
           0.0029        49.8717      0.0232812            454           1489          11920
           0.0029        58.4047      0.0232812            844           1490          11920
           0.0031        104.326      0.0243516           1532           1559          12468
           0.0031        76.0039      0.0242402            946           1550          12411
           0.0031        108.309      0.0252871            819           1619          12947
           0.0031        118.408      0.0257383           2280           1647          13178
           0.0031         118.31      0.0243027           1106           1554          12443
           0.0031        99.5767      0.0255536           1007           1611          12879
           0.0031        104.061      0.0259226            876           1633          13065
           0.0031        56.0614      0.0249512            587           1597          12775
           0.0031        72.3613      0.0253313            717           1597          12767
           0.0031        64.9232      0.0241845            687           1524          12189
           0.0031        53.4655      0.0240313            626           1538          12304
           0.0031        124.637      0.0246582           2329           1578          12625
           0.0031        94.2219      0.0251621            814           1609          12883
           0.0031        62.6972      0.0246835            485           1529          12243
           0.0031         78.491      0.0250918           1028           1605          12847
           0.0031        126.216      0.0257956           1980           1626          13001
           0.0031         140.55      0.0254727           1372           1630          13042
           0.0031        153.543      0.0264277           1637           1692          13531
           0.0031        60.6328      0.0249297            640           1596          12764
           0.0031         85.134      0.0243887            671           1560          12487
           0.0033        118.593      0.0267778           1307           1687          13496
           0.0033        139.748      0.0266406           2309           1704          13640
           0.0033        82.8005      0.0257793           1164           1649          13199
           0.0033        298.774      0.0258809           2956           1656          13251
           0.0033        170.691      0.0256973           2203           1645          13157
           0.0033        147.951      0.0260801           1680           1670          13353
           0.0033        209.779      0.0264043           1740           1690          13519
           0.0033        113.082      0.0267798            925           1686          13497
           0.0033        281.784      0.0260137           2693           1665          13319
           0.0033        93.5012      0.0267637           1262           1714          13703
           0.0033        183.521      0.0265234           3309           1698          13580
           0.0033        318.505       0.026334           3611           1684          13483
           0.0033        184.512      0.0250957           3788           1606          12849
           0.0033        84.2518       0.025959           1072           1660          13291
           0.0033        232.419      0.0260081           3363           1612          12900
           0.0033        159.583      0.0257676           2077           1649          13193
           0.0033        101.356      0.0257148           1725           1647          13166
           0.0033        332.733      0.0266641           3810           1706          13652
           0.0033        214.256      0.0261406           2603           1672          13384
           0.0033        155.221      0.0262852           1391           1683          13458
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
